<?php
/**
 * Function:
 * Description:
 * Abo 2018/10/12 10:17
 * Email: abo2013@foxmail.com
 */

/**
 * 以下方式不行:onRequest()，onReceive()，onConnect()callback回调函数内使用s
    $redis = new Swoole\Coroutine\Redis();
    $redis->connect( '127.0.0.1', 6379 );
    $redis->get( 'key' );
 */

$http = new swoole_http_server( '0.0.0.0', 8001 );
$http->on( 'request', function( $request, $response ) {
    $redis = new \Swoole\Coroutine\Redis();

    $redis->connect( '127.0.0.1', 6379 );
    $value = $redis->get( $request->get[ 'a' ] );

    // Mysql查询

    // 耗时 = max( mysql_select, redis_get ) 中最大值
    $response->header( 'Content-Type', 'text/plain' );
    $response->end( $value );
} );

$http->start();